home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
emsif24a.zip
/
EMSTEST3.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-01
|
48KB
|
1,187 lines
/***************************************************************************
* emstest3.c *
* MODULE: EMSIF *
* OS: DOS *
* VERSION: 1.2 *
* DATE: 12/01/91 *
* *
* Copyright (c) 1991 James W. Birdsall. All Rights Reserved. *
* *
* Requires emsif.h, testutil.h, and emstest.h to compile. *
* Compiles under Borland C++ 2.0, TC 2.0, or MSC 6.0A. *
* *
* Regression test and example for EMSIF. See EMSTEST.C for more info. *
* *
***************************************************************************/
/*
** system includes <>
*/
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <string.h>
/* include appropriate file according to compiler */
#ifdef __TURBOC__
#include <alloc.h>
#else
#include <malloc.h>
#endif
/*
** custom includes ""
*/
#include "testutil.h"
#include "emsif.h"
#include "emstest.h"
/*
** local #defines
*/
#define UCF unsigned char far
#define UCH unsigned char huge
/*
** Define LMALLOC() and LFREE() to the appropriate functions, according to
** compiler.
*/
#ifdef __TURBOC__
#define LMALLOC(kbytes) farmalloc((((unsigned long) kbytes) * 1024L))
#define LFREE(ptr) farfree((ptr))
#else
#define LMALLOC(kbytes) halloc((kbytes), 1024)
#define LFREE(ptr) hfree((ptr))
#endif
/*
** This macro is the same as TRIPLECHECK(), defined in EMSTEST.H, except that
** it calls functions which can handle a far pointer.
*/
#define LTRIPLECHECK(fu, st, ex, fr1, fr2, fr3) \
lfailcheck((fu), (st), (fr1), (fr2), (fr3)); \
lweirdretchk((fu), (st), (fr1), (fr2), (fr3)); \
lweirdcodechk((fu), (ex), (fr1), (fr2), (fr3))
/*
** Checks to see if a region of memory (possibly longer than 64K) is still
** incrementing word values, handles cleanup and exit if not.
*/
#define WORDCHECK(buf, len, msg, start) \
if (lfarincwordcheck((buf), (len), (start)) != 0) { \
printf("Copy corrupted %s.\n", (msg)); EMMfree(handle); \
LFREE(testbuf); exit(3); }
/*
** Check source and destination buffers, respectively.
*/
#define SRCWORDCHECK(buf, len) WORDCHECK(buf, len, "source buffer", 0)
#define CPYWORDCHECK(buf, len) WORDCHECK(buf, len, "copied bytes", 0)
/*
** Checks to see if a region of memory (possibly longer than 64K) is still
** filled with a given value, handles cleanup and exit if not.
*/
#define MEMCHECK(buf, len, val) \
if (lfarmemcheck((UCF *) (buf), (len), (val)) != 0) { \
printf("Copy corrupted destination.\n"); \
EMMfree(handle); LFREE(testbuf); exit(3); }
/*
** Checks buffer for nonzero values.
*/
#define ZEROCHECK(buf, len) MEMCHECK(buf, len, '\0')
/*
** misc: copyright strings, version macros, etc.
*/
/*
** typedefs
*/
/*
** global variables
*/
/* see EMSTEST.C for info */
extern int testno;
extern unsigned char far *frameptr[];
extern char *gblmsg;
/*
** static globals
*/
/*
** function prototypes
*/
static void do_nlongcopy_tests(void);
static void do_ilongcopy_tests(void);
static void lfailcheck(char *function, int status, void far *tofree1,
int tofree2, int tofree3);
static void lnofailcheck(char *function, int status, void far *tofree1,
int tofree2, int tofree3);
static void lweirdretchk(char *function, int status, void far *tofree1,
int tofree2, int tofree3);
static void lweirdcodechk(char *function, int expected, void far *tofree1,
int tofree2, int tofree3);
/*
** functions
*/
/***************************************************************************
* FUNCTION: DO_LONGCOPY_TESTS *
* *
* DESCRIPTION: *
* *
* Central dispatching function for long copy tests. *
* *
* ENTRY: *
* *
* Void. *
* *
* EXIT: *
* *
* Void. *
* *
* CONSTRAINTS/SIDE EFFECTS: *
* *
***************************************************************************/
void do_longcopy_tests(void)
{
do_nlongcopy_tests();
do_ilongcopy_tests();
return;
} /* end of do_longcopy_tests() */
/***************************************************************************
* FUNCTION: DO_NLONGCOPY_TESTS (STATIC) *
* *
* DESCRIPTION: *
* *
* Tests EMSIF functions EMMcopyto() and EMMcopyfrom() with copies *
* longer than one EMS page ( > 16384 bytes). *
* *
* ENTRY: *
* *
* Void. *
* *
* EXIT: *
* *
* Void. *
* *
* CONSTRAINTS/SIDE EFFECTS: *
* *
***************************************************************************/
static void do_nlongcopy_tests(void)
{
unsigned char far *testbuf;
int handle;
int status;
unsigned long ticks, totticks;
int loop;
unsigned long loop2;
/* allocate memory to test against */
testbuf = (unsigned char far *) LMALLOC(80);
if (testbuf == (unsigned char far *) NULL)
{
printf("Cannot allocate test memory. Aborting.\n");
exit(1);
}
/* now allocate some EMS to test with */
handle = test_EMMalloc(81920L);
/* fill test buffer with incrementing word pattern */
lfarincwordfill(testbuf,